<!--
 * @Descripttion: 大屏报表卡片列表
 * @Author: Devli
 * @Date: 2021-3-19 10:23:24
 * @Last Modified by:   qianlishi
 * @Last Modified time: 2021-3-13 11:04:24
 !-->
<template>
  <div class="main-layout">
    <el-row :gutter="24">
      <el-col :span="6">
        <SideTree @fromSideTree="queryScreenList({
          page: 1,
          size: 10,
        })" @treeClick="treeClickSearch" class="sidebar-container" ref="SideTree" />
      </el-col>
      <el-col :span="18">
        <!-- ------------------------------------- 头部栏 ------------------------------------ -->
        <el-form ref="form" :model="params" :rules="rules" label-width="120px">
          <!-- 搜索 -->
          <el-row :gutter="10">
            <el-col :xs="24" :sm="20" :md="12" :lg="6" :xl="4">
              <el-form-item label="名称">
                <el-input v-model="params.reportName" size="mini" clearable placeholder="名称" class="filter-item" />
              </el-form-item>
            </el-col>
            <!-- <el-col :xs="24" :sm="20" :md="12" :lg="6" :xl="4">
              <el-form-item label="报表编码">
                <el-input v-model="params.reportCode" size="mini" clearable placeholder="报表编码" class="filter-item" />
              </el-form-item>
            </el-col> -->
            <el-col :xs="24" :sm="20" :md="4" :lg="4" :xl="4">
              <el-button type="primary" size="mini" @click="search(params.reportName)">查询</el-button>
              <el-button type="danger" size="mini" @click="reset('form')">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
        <!-- ------------------------------------- 大屏列表 ----------------------------------- -->
        <el-row :gutter="20">
          <el-col v-for="item in list" :key="item.id" :span="6">
            <div class="bg">
              <img class="bg-img" :src="require('@/assets/images/charts.jpg')" />
              <div class="content">
                <header>{{ item.reportName }}</header>
                <footer>
                  {{ item.updateTime }}
                  <div class="operation">
                    <el-button class="view" type="text" @click="viewDesign(item)"
                      v-permission="'bigScreenManage:view'">查看</el-button>
                    <el-button class="edit" type="text" @click="openDesign(item)"
                      v-permission="'bigScreenManage:design'">编辑</el-button>
                    <el-button class="edit" type="text" @click="updateDesign(item)"
                      v-permission="'bigScreenManage:design'">修改</el-button>
                    <el-button class="edit" type="text" @click="deleteDesign(item)"
                      v-permission="'bigScreenManage:design'">删除</el-button>
                  </div>
                </footer>
              </div>
            </div>
          </el-col>
        </el-row>
        <div class="block">
          <el-pagination :total="totalCount" :page-sizes="[10, 20, 50, 100]" :page-size="params.size"
            :current-page="params.page" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
        </div>
      </el-col>
    </el-row>
    <confirmDialog @fromcomfirm="queryScreenList(params)" ref="confirmDialog" />
  </div>
</template>

<script>
import confirmDialog from "./SideTree/confirmDialog.vue"
import SideTree  from "./SideTree/index.vue";
import { getScreenListApi, getTreeList, deleteScreen } from "@/api/newApi/screenPart"
export default {
  name: "Login",
  components: { confirmDialog, SideTree },
  data() {
    return {
      likeName: "",
      list: [],
      rules: {},
      totalCount: 0,
      params: {
        reportName: "",
        reportGroupId: null,
        page: 1,
        size: 10,
      },
      // 分享
      visibleForShareDialog: false,
      reportCodeForShareDialog: "",
      reportNameForShareDialog: "",
      reportTypeForShareDialog: "",
    };
  },
  mounted() { },
  created() {
    this.queryScreenList(this.params)
    this.queryTreeList()
  },
  methods: {
    // ============================== 头部查询部分 ================================
    // 查询
    search() {
      this.queryScreenList(this.params);
    },
    treeClickSearch(data) {
      if (data.id == "1") {
        this.params.reportGroupId = ""
      } else {
        this.params.reportGroupId = data.id
      }
      this.queryScreenList(this.params);
    },
    // 重置
    reset(formName) {
      this.$refs[formName].resetFields();
      this.params.reportName = "";
      this.params.reportCode = "";
      this.params.pageNumber = 1;
      this.queryScreenList(params);
    },
    // ============================== 大屏列表部分 ================================
    // 请求大屏列表
    async queryScreenList(params) {
      let res = await getScreenListApi(params)
      this.list = res.data.list
      this.totalCount = res.data.total
      console.log(res, "11111111111111111");
    },
    updateDesign(item) {
      console.log(item, "ooooooooooooo");
      this.$refs.confirmDialog.dialogVisible = true
      this.$refs.confirmDialog.isUpdate = true
      this.$refs.confirmDialog.form = {
        id: item.id,
        reportName: item.reportName,
        reportGroupId: item.reportGroupId,  // 左侧树id
        reportTaskId: item.reportTaskId, // 任务
        reportDesc: item.reportDesc,  // 描述
        reportType: item.reportType,
        reportImage: item.reportImage,
        screenSize: Number(item.screenSize)
      }
    },
    deleteDesign(item) {
      let _self = this
      deleteScreen({
        id: item.id
      }).then((res) => {
        if (res.code == 200) {
          _self.$message({
            type: "success",
            message: "删除成功"
          })
          _self.queryScreenList(_self.params)
        }
      })
    },
    // ============================== 页码部分 ============================
    handleSizeChange(val) {
      this.params.size = val;
      this.queryScreenList(this.params);
    },
    handleCurrentChange(val) {
      this.params.page = val;
      this.queryScreenList(this.params);
    },

    // 请求树结构
    async queryTreeList() {
      let res = await getTreeList()
      console.log(res, "11111111");
      this.$refs.SideTree.setTreeData(res)
    },

    // 编辑页面相关
    openDesign(val) {
      console.log(val, "111111111111");
      
      let routeUrl = this.$router.resolve({
        //path: "/screenDesigner",
        path: "/bigscreen/designer",
        query: {
          id: val.id,
          reportTaskId: val.reportTaskId,
          screenSize: val.screenSize
          // screenSize: val.screenSize
        }
      });
      window.open(routeUrl.href, "_blank");
    },
    viewDesign(val) {
      let routeUrl = this.$router.resolve({
        path: "/bigscreen/viewer",
        query: { id: val.id }
      });
      window.open(routeUrl.href, "_blank");
    }
  }
};
</script>

<style lang="scss">
.main-layout {
  position: relative;
  height: auto;
  background: #fff;
  width: 100vw;

  header {
    font-size: 24px;
    text-align: center;
    line-height: 80px;
  }

  .bg {
    width: 100%;
    height: 200px;
    position: relative;
    overflow: hidden;
    margin: 10px 0;
    border: 12px solid white;
  }

  .bg .bg-img {
    position: absolute;
    width: 100%;
    height: 100%;
    filter: blur(6px);
    z-index: 2;
  }

  .content {
    width: 100%;
    height: 100%;
    position: absolute;
    color: #fff;
    left: 0;
    top: 0;
    z-index: 3;
  }

  footer {
    width: 100%;
    font-size: 14px;
    padding: 16px;
    line-height: 30px;
    position: absolute;
    z-index: 3;
    bottom: 0;

    .operation {
      float: right;

      .view,
      .edit {
        color: #fff;
        font-size: 14px;
      }
    }
  }
}
</style>
